// @FileName  :sort.c
// @Time      :2024/3/7 11:47
// @Author    :YKW
//# include <bits/stdc++.h>
//using namespace std;
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>

struct info {
    char name[30];
    char phone[20];
    int num;
} book[50];


int cmp(const void *a, const void *b) {
    struct info *s1 = (struct info **) a;
    struct info *s2 = (struct info **) b;
    return strcmp(s1->name, s2->name);
}

void main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s%s", book[i].name, book[i].phone);
        for (int j = 0; j < i; j++) {
            if (strcmp(book[i].name, book[j].name) == 0 && strcmp(book[i].phone, book[j].phone) == 0) {
                i--;
                n--;
                continue;
            }
            if (strcmp(book[i].name, book[j].name) == 0) {
                book[j].num++;
                book[i].name[strlen(book[i].name)] = '_';
                book[i].name[strlen(book[i].name)] = book[j].num - 0 + '0';
            }
        }
    }
    qsort(book, n, sizeof(struct info), cmp);
    for (int i = 0; i < n; i++) {
        printf("%s %s\n", book[i].name, book[i].phone);
    }
}